package com.zzyy.study.controller;

import com.zzyy.study.mapper.AccountMapper;
import com.zzyy.study.resp.ResultData;
import com.zzyy.study.service.AccountService;
import com.zzyy.study.service.AccountTCCService;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * @auther zzyy
 * @create 2023-12-08 18:04
 */
@RestController
public class AccountController
{
    @Resource
    private AccountService accountService;
    @Resource
    private AccountTCCService accountTCCService;

    /**
     * 扣减账户余额AT-XA
     */
    @RequestMapping("/account/decrease")
    public ResultData decrease(@RequestParam("userId") Long userId, @RequestParam("money") Long money){
        accountService.decrease(userId,money);
        return ResultData.success("扣减账户余额成功！");
    }

    /**
     * 扣减账户余额TCC
     */
    @PostMapping("account/decreasetcc")
    ResultData decreaseTcc(@RequestParam("userId") Long userId, @RequestParam("money") Long money)
    {
        accountTCCService.decreaseTcc(userId,money);
        return ResultData.success("tcc扣减账户余额成功！");
    }
}
